package com.sxs.handler;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 当登录成功后,该处理类的方法被调用
 */

@Component
public class LoginSuccessHandler implements AuthenticationSuccessHandler {
    @Autowired
//    private JwtUtils jwtUtil;
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        System.out.println("执行登录成功的方法");
        response.setContentType("application/json;charset=UTF-8");
        ServletOutputStream outputStream = response.getOutputStream();
        // 生成jwt返回
//        String token = jwtUtil.generateToken(authentication.getName());
        System.out.println("登陆成功");
//        response.setHeader(jwtUtil.getHeader(), token);
//        outputStream.write(token.getBytes("UTF-8"));
        outputStream.flush();
        outputStream.close();

    }


}
